package com.suning.sawp.web.controller;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.suning.sawp.constants.ErrorCodeConstants;
import com.suning.sawp.intf.assistant.AssistantService;
import com.suning.sawp.intf.assistant.Result;
import com.suning.sawp.po.assistant.Assistant;
import com.suning.sawp.service.util.BaseContants;
import com.suning.sawp.web.exception.MyGsonView;
/**
 * 
 * 店+小助手业务控制类<br> 
 * 〈功能详细描述〉
 *
 * @author 12061818
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
@Controller
@RequestMapping("/assistant")
public class AssistantController extends DjBaseController{
    
    private static final Logger LOGGER = LoggerFactory.getLogger(AssistantController.class);
    
    @Autowired
    AssistantService assistantService;
    
    @RequestMapping("/setupAssistant.do")
    public MyGsonView setupAssistant(String staffId){
        MyGsonView res = createGsonView();
        if(StringUtils.isBlank(staffId)){
            setErrorMsg(res,ErrorCodeConstants.ERR_0001);
            return res;
        }
        
        Result<Assistant> result = null;
        try {
            result = assistantService.setupAssistant(staffId);
        } catch (Exception e) {
            LOGGER.error("setupAssistant error.", e);
            setErrorMsg(res,ErrorCodeConstants.ERR_0005);
            return res;
        }
        
        if(result.getSuccessFlg().equals(BaseContants.FAILED)){
            setErrorMsg(res,ErrorCodeConstants.ERR_0005);
            return res;
        }
        res.addStaticAttribute("assistant", result.getData());
        return res;
    }
}
